<template>
  <div class="resident-container">
    <!-- 数据表格 -->
    <el-table
        :data="tableData"
        border
        stripe
        v-loading="loading"
        style="width: 100%">
      <!-- 左侧列 -->
      <el-table-column type="index" label="序号" width="60" align="center" />
      <el-table-column prop="name" label="姓名" width="120" align="center" />
      <el-table-column prop="phone" label="手机号" width="130" align="center" />
      <el-table-column prop="idCard" label="身份证号" width="200" align="center">
        <template #default="scope">
          {{ scope.row.idCard || '-' }}
        </template>
      </el-table-column>

      <!-- 右侧列 -->
      <el-table-column prop="relationship" label="关系" width="100" align="center">
        <template #default="scope">
          <el-tag :type="scope.row.relationship === '家属' ? 'success' : 'warning'">
            {{ scope.row.relationship }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="isRegistered" label="是否注册" width="100" align="center">
        <template #default="scope">
          <el-tag :type="scope.row.isRegistered === '是' ? 'success' : 'info'">
            {{ scope.row.isRegistered }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="remark" label="备注" min-width="150" show-overflow-tooltip>
        <template #default="scope">
          {{ scope.row.remark || '-' }}
        </template>
      </el-table-column>
    </el-table>

    <!-- 空状态 -->
    <el-empty v-if="tableData.length === 0 && !loading" description="暂无成员信息" />
  </div>
</template>

<script setup name="ResidentCard">
import { ref, onMounted, watch } from 'vue'

// 定义props
const props = defineProps({
  residentData: {
    type: Array,
    default: () => []
  }
})

const tableData = ref([])
const loading = ref(false)

// 监听props变化
watch(
    () => props.residentData,
    (newData) => {
      tableData.value = newData
    },
    { immediate: true, deep: true }
)

// 初始化数据
onMounted(() => {
  console.log('住户数据:', props.residentData)
})
</script>

<style scoped lang="scss">
.resident-container {
  padding: 0;

  :deep(.el-table) {
    .el-table__header-wrapper {
      background-color: #f5f7fa;
    }

    .el-table__row {
      &:hover {
        background-color: #f5f7fa;
      }
    }
  }
}
</style>